package org.snail.web.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;

import javax.sql.DataSource;

/**
 * Created by WJ on 2017/12/8.
 */
@Configuration
public class TransactionManagerElConfig {

    @Autowired
    @Qualifier("platformTomcat")
    private DataSource platformTomcat;

//    暂时没有配置这个类
//    @Autowired
////    @Qualifier("platformReadTomcat")
//    private DataSource platformReadTomcat;

    @Bean(name = "jdbcTemplate")
    public JdbcTemplate jdbcTemplate() {
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(platformTomcat);
        return jdbcTemplate;
    }

//    这个可能是分布式的，暂时注释掉
//    @Bean(name = "jdbcReadTemplate")
//    @Bean(name = "jdbcReadTemplate")
//    public JdbcTemplate jdbcReadTemplate() {
//        JdbcTemplate jdbcReadTemplate = new JdbcTemplate();
//        jdbcReadTemplate.setDataSource(platformReadTomcat);
//        return jdbcReadTemplate;
//    }

    @Bean(name = "transactionManager")
    public DataSourceTransactionManager transactionManager() {
        DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();
        transactionManager.setDataSource(platformTomcat);
        return transactionManager;
    }

}
